//
//  LSPersonalHomePageHeadView.m
//  LookScore
//
//  Created by wr on 2017/12/18.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSPersonalHomePageHeadView.h"
#import <UIButton+WebCache.h>

@implementation LSPersonalHomePageHeadView

-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        [self addContentView];
    }
    return self;
}

-(void)addContentView{
    
    UIView *topView=[[UIView alloc]init];
    topView.backgroundColor=LSNavMainColor;
    [self addSubview:topView];
    topView.sd_layout
    .leftEqualToView(self)
    .topEqualToView(self)
    .rightSpaceToView(self,0)
    .heightIs(LSStatusBarHeight);
    
    
    UIImageView *backImageView=[[UIImageView alloc]init];
    backImageView.image=[UIImage imageNamed:@"MineHead"];
    [self addSubview:backImageView];
    backImageView.userInteractionEnabled=YES;
    backImageView.sd_layout
    .leftEqualToView(self)
    .topEqualToView(topView)
    .rightEqualToView(topView)
    .bottomEqualToView(self);
    
//    UIButton *reportBu=[[UIButton alloc]init];
//    [reportBu setBackgroundImage:[UIImage imageNamed:@"举报"] forState:UIControlStateNormal];
//    reportBu.backgroundColor = [UIColor redColor];
////    reportBu.titleLabel.textColor=LSTitleWhiteColor;
////    reportBu.titleLabel.font=LSFontSize12;
//    [reportBu addTarget:self action:@selector(clickReportBu:) forControlEvents:UIControlEventTouchUpInside];
//    [backImageView addSubview:reportBu];
//    self.reportBu=reportBu;
//    reportBu.sd_layout.rightEqualToView(backImageView).offset(-10).topEqualToView(backImageView).offset(20).widthIs(30).heightIs(30);
    
    UIButton *headImgBu=[[UIButton alloc]init];
//    [headImgBu setBackgroundImage:[UIImage imageNamed:@"MineDefaultHead"] forState:UIControlStateNormal];
    headImgBu.titleLabel.textColor=LSTitleWhiteColor;
    headImgBu.titleLabel.font=LSFontSize12;
    [headImgBu addTarget:self action:@selector(ReplacePhotoAction) forControlEvents:UIControlEventTouchUpInside];
    [backImageView addSubview:headImgBu];
    self.headImgBu=headImgBu;
    headImgBu.sd_layout.centerXEqualToView(backImageView).topEqualToView(backImageView).offset(40).widthIs(80).heightIs(80);
    
    UILabel *nameLab=[[UILabel alloc]init];
    nameLab.font=LSFontSize15;
    nameLab.textColor=LSTitleWhiteColor;
    nameLab.textAlignment=NSTextAlignmentCenter;
    
    [backImageView addSubview:nameLab];
    self.nameLab=nameLab;
    nameLab.sd_layout.topSpaceToView(headImgBu,5).centerXEqualToView(backImageView).widthIs(200).heightIs(20);
    
    
    UIButton *attentionBu=[[UIButton alloc]init];
    attentionBu.titleLabel.textColor=LSTitleWhiteColor;
    attentionBu.titleLabel.font=LSFontSize10;
    [attentionBu setImage:[UIImage imageNamed:@"attend"] forState:UIControlStateNormal];
    [attentionBu setImage:[UIImage imageNamed:@"selectAttend"] forState:UIControlStateSelected];
//    [attentionBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor9dd3cc] forState:UIControlStateNormal];
//    [attentionBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor7ec5fd] forState:UIControlStateSelected];
//    [attentionBu setTitle:@"+关注" forState:UIControlStateNormal];
//    [attentionBu setTitle:@"已关注" forState:UIControlStateSelected];
    attentionBu.layer.masksToBounds=YES;
    attentionBu.layer.cornerRadius=8;
    [attentionBu addTarget:self action:@selector(attentionEvent:) forControlEvents:UIControlEventTouchUpInside];
    [backImageView addSubview:attentionBu];
    self.attentionBu=attentionBu;
    attentionBu.sd_layout.leftSpaceToView(headImgBu, 5).centerYEqualToView(headImgBu).offset(30).widthIs(55)
    .heightIs(24);
    
    UIButton *introduceBu=[[UIButton alloc]init];
    introduceBu.titleLabel.font=LSFontSize12;
    [introduceBu setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
    introduceBu.titleLabel.numberOfLines = 0;
    
    introduceBu.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
    
    [introduceBu setTitleEdgeInsets:UIEdgeInsetsMake(10, 30, 10, 10)];
    introduceBu.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
    [introduceBu setImage:[UIImage imageNamed:@"MineEdit"] forState:UIControlStateNormal];
//    introduceBu.titleEdgeInsets=UIEdgeInsetsMake(0, 0, 0, -10);
    [introduceBu addTarget:self action:@selector(editIntroduce:) forControlEvents:UIControlEventTouchUpInside];
    [backImageView addSubview:introduceBu];
    self.introduceBu=introduceBu;
    introduceBu.sd_layout.leftEqualToView(backImageView ).topSpaceToView(nameLab,15).rightEqualToView(backImageView).heightIs(20);
    
    
    LSTopSegmentSortView *sortView=[[LSTopSegmentSortView alloc]initWithFrame:CGRectMake(0, 0, self.width,43)];
    sortView.backgroundColor=LSNavMainColor;
    sortView.unSelectedColor=LSTitleWhiteColor;
    sortView.selectedColor=LSNavTitlenColor;
//    [sortView addBottomArray:self.bottomArray selectButton:0];
    [backImageView addSubview:sortView];
    self.sortView=sortView;
    sortView.sd_layout.leftEqualToView(backImageView).bottomEqualToView(backImageView).heightIs(43).rightEqualToView(backImageView);
    
    
 
    
//  updateLayout
//    [self addFasleData];
}

- (void)setBottomArray:(NSArray *)bottomArray{
    _bottomArray = bottomArray;
    [self.sortView addBottomArray:bottomArray selectButton:0];
    
}

- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    
    if ([dict[@"IsAttended"] isEqual:@(YES)]) {
        self.attentionBu.selected = YES;
    }else{
        self.attentionBu.selected = NO;
    }
    
    [self.headImgBu sd_setBackgroundImageWithURL:[NSURL URLWithString:dict[@"UserHeadUrl"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    self.nameLab.text = dict[@"DisplayName"];
    
    if ([CommonClass isBlankString:dict[@"SpecialWords"]]) {
        [self.introduceBu setTitle:@"这个人有点懒什么也没留下" forState:UIControlStateNormal];
    }else{
        [self.introduceBu setTitle:dict[@"SpecialWords"] forState:UIControlStateNormal];
    }
}

-(void)addFasleData{
    [self.headImgBu sd_setBackgroundImageWithURL:[NSURL URLWithString:[LSAccountArchive account].UserHeadUrl] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    
//    if ([LSAccountArchive account].UserHeadUrl.length == 0) {
//        [self.headImgBu sd_setBackgroundImageWithURL:[NSURL URLWithString:@"MineDefaultHead"] forState:UIControlStateNormal];
//    }else{
//        [self.headImgBu sd_setBackgroundImageWithURL:[NSURL URLWithString:[LSAccountArchive account].UserHeadUrl] forState:UIControlStateNormal];
//    }
    
    self.nameLab.text = [LSAccountArchive account].DisplayName;
    
    
    if ([LSAccountArchive account].SpecialWords.length == 0) {
        [self.introduceBu setTitle:@"这个人有点懒什么也没留下" forState:UIControlStateNormal];
    }else{
        [self.introduceBu setTitle:[LSAccountArchive account].SpecialWords forState:UIControlStateNormal];
    }
}

- (void)editIntroduce:(UIButton *)sender{
    if (self.EditIntroduceBlock) {
        self.EditIntroduceBlock();
    }
}

- (void)ReplacePhotoAction{
    if (self.ReplacePhotoBlock) {
        self.ReplacePhotoBlock();
    }
}
- (void)attentionEvent:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (self.AttentionActionBlock) {
        self.AttentionActionBlock(sender);
    }
}
- (void)clickReportBu:(UIButton *)sender{
    if (self.ReportBlock) {
        self.ReportBlock(sender);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
